package com.springboot.rabbitmq.route;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author: lzx
 * @Data: 2021/04/29/14:15
 * @Description：
 */
@Component
public class DirectRouteCustomer {
    // 1.声明交换机和交换机类型 2.声明队列 3.绑定路由键
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,
                    exchange = @Exchange(value = "directs", type = "direct"), //指定交换机名称和类型 默认是direct
                    key = {"info", "error"}
            )
    })
    public void receive1(String message) {
        System.out.println("消费者1  key = {\"info\", \"error\"}:" + message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,
                    exchange = @Exchange("directs"), //指定交换机名称和类型 默认是direct
                    key = {"error"}
            )
    })
    public void receive2(String message) {
        System.out.println("消费者2  key = {\"error\"}:" + message);
    }


}
